function firstCall() {

    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "http://127.0.0.1:3000/req/first",
        "method": "post",
        "headers": {
        },
        "processData": false,
        "error": function (xhr, textStatus, errorThrown) {
            /*错误信息处理*/
            alert("进入error---");
            alert("状态码：" + xhr.status);
            alert("状态:" + xhr.readyState);//当前状态,0-未初始化，1-正在载入，2-已经载入，3-数据进行交互，4-完成。
            alert("错误信息:" + xhr.statusText);
            alert("返回响应信息：" + xhr.responseText);//这里是详细的信息
            alert("请求状态：" + textStatus);
            alert(errorThrown);
            alert("请求失败");
        },
        "success": function (response, textStatus, xhr) {
            var httpStatus = xhr.status;
            var status = getStatus(response, httpStatus);
            var data = format(response, httpStatus);
            showData('firstData', data);
            showStatus('firstStatus', status);
        }
    }

    $.ajax(settings);
}

function format(data, httpStatus) {
    // let newStr = '';
    let newStr = 'httpStatusCode:' + httpStatus + '</br>' + JSON.stringify(data);
    // for (let key in data) {
    //     let value = data[key];
    //     newStr = newStr + key + ':' + value + '</br>';
    // }
    return newStr
}

function getStatus(data, httpStatus) {
    let status = '';
    if (data["errorCode"]) {
        let code = data["errorCode"]
        let l = code.length;
        for (let i = l - 3; i < l; i++) {
            status = status + code[i]
        }
       
    }else{
        status = httpStatus;
    }
    return status;
}

function showData(id, str) {
    let cell = document.getElementById(id);
    cell.innerHTML = str;
}

function showStatus(id, status) {
    let cell = document.getElementById(id);
    if (status == 200) {
        cell.innerHTML = status;
        cell.style.color = "#27cc27";
    } else {
        cell.innerHTML = status;
        cell.style.color = "red";
    }
}

function logout() {
    var settings = {
        "async": true,
        "crossDomain": true,
        "url": "http://127.0.0.1:8500/logout",
        "method": "get",
        "success": function (response) {
            console.log(response);
            if (response.ret_code == 200) {
                location.href = 'http://127.0.0.1:5500' + response.ret_url;
            }
            if (response.ret_code == 1) {
                alert("服务器错误！请稍后再试");
            }

        }
    }

    $.ajax(settings);
}

